<?php
session_start();
require "lib/db.php";
require "lib/customer-function.php";
require "lib/address-function.php";
require "lib/customertype-function.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Customer</title>
<link rel="stylesheet" type="text/css" href="css/home.css">
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>

<script>
	$(document).ready(function() {
			$("#customer").css({"background-color":"#FFF",	
	"color":"#000"});
    });
</script>
<style>
	#content{
		overflow:scroll;
		height:510px;
		margin:2px 3px;
		opacity:0.8;
		text-align:center;
	}

</style>
</head>

<body>

<!--menu-->
<?php
require "menu.php";
?>

<!--content-->
<div id="content">
<table width="100%" border="1" cellspacing="0">
  <tr>
    <th colspan="15">List Customers</th>
  </tr>
  <tr>
    <th>CustomerID</th>
    <th>Category Name</th>
    <th>Birthday</th>
    <th>Email</th>
    <th>Phone</th>
    <th>House Number</th>
    <th>Street</th>
    <th>Ward</th>
    <th>District</th>
    <th>City</th>
    <th>Customer Type</th>
    <th>Register Year</th>
    <th>Register Month</th>
    <th>Customer Amount Total</th>
    <th><a href="add-customer.php">Add Customer</a></th>
  </tr>
	<?php
    $listcustomer = getAllCustomer();
	while($customer = mysql_fetch_array($listcustomer)){
		$addressID = $customer['AddressID'];
		settype($addressID,"int");
		$address = mysql_fetch_array(getAddressByID($addressID));
		
		$customerTypeID = $customer['CustomerTypeID'];
		settype($customerTypeID,"int");
		$customerType = mysql_fetch_array(getCustomerTypeByID($customerTypeID));
		
		ob_start();
    ?>
  <tr>
    <td>{CustomerID}</td>
    <td>{CustomerName}</td>
    <td>{Birthday}</td>
    <td>{Email}</td>
    <td>{Phone}</td>
    <td>{HouseNumber}</td>
    <td>{Street}</td>
    <td>{Ward}</td>
    <td>{District}</td>
    <td>{City}</td>
    <td>{CustomerType}</td>
    <td>{RegisterYear}</td>
    <td>{RegisterMonth}</td>
    <td>{CustomerAmountTotal}</td>
    <td><a href="edit-customer.php?customerid={CustomerID}">Edit</a> - <a onClick="return confirm('Are you sure delete this customer?');" href="delete-customer.php?customerid={CustomerID}">Delete</a></td>
  </tr>
 	<?php 
	$s = ob_get_clean();
	$s = str_replace("{CustomerID}","$customer[CustomerID]",$s);
	$s = str_replace("{CustomerName}","$customer[CustomerName]",$s);
	$s = str_replace("{Birthday}","$customer[Birthday]",$s);
	$s = str_replace("{Email}","$customer[Email]",$s);
	$s = str_replace("{Phone}","$customer[Phone]",$s);
	$s = str_replace("{HouseNumber}","$address[HouseNumber]",$s);
	$s = str_replace("{Street}","$address[Street]",$s);
	$s = str_replace("{Ward}","$address[Ward]",$s);
	$s = str_replace("{District}","$address[District]",$s);
	$s = str_replace("{City}","$address[City]",$s);
	$s = str_replace("{CustomerType}","$customerType[CustomerType]",$s);
	$s = str_replace("{RegisterYear}","$customer[RegisterYear]",$s);
	$s = str_replace("{RegisterMonth}","$customer[RegisterMonth]",$s);
	$s = str_replace("{CustomerAmountTotal}","$customer[CustomerAmountTotal]",$s);
	echo $s;
	}
	?>
</table>

</div>

<!--footer-->
<?php
require "footer.php";
?>

</body>
</html>